﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using DatabaseComponent;

namespace DatabaseComponent
{
    public class OrganizationHier : IHierarchyData
    {

        public OrganizationHier(OrgnizationChart objOrgnizationChartIn)
            : base()
        {
            objOrgnizationChart = objOrgnizationChartIn;

        }


        OrgnizationChart _objOrgnizationChart = new OrgnizationChart();

        public OrgnizationChart objOrgnizationChart
        {
            get { return _objOrgnizationChart; }
            set { _objOrgnizationChart = value;
            
            
            }
        }

        



        public string NameEN
        {
            get
            {
                return _objOrgnizationChart.NameEN;
            }
        }


        public string NameAR
        {
            get
            {
                return _objOrgnizationChart.NameAR;
            }
        }

        public long ID
        {
            get
            {
                return _objOrgnizationChart.ID;
            }
        }



        public string TypeImageUrl
        {
            get
            {
                string strType = _objOrgnizationChart.objChartType.TypeNameEN;

                strType += ".jpg";

                strType = "~/LmsWebSite/getImage.ashx?image=./images/" + strType + "&w=30&h=30&color=white";

                return strType;

            }
        }



        // Summary:
        //     Indicates whether the hierarchical data node that the System.Web.UI.IHierarchyData
        //     object represents has any child nodes.
        //
        // Returns:
        //     true if the current node has child nodes; otherwise, false.
        public bool HasChildren {

            get
            {
                return (_objOrgnizationChart.lstChild.Count > 0);
            }
        
        
        }
        //
        // Summary:
        //     Gets the hierarchical data node that the System.Web.UI.IHierarchyData object
        //     represents.
        //
        // Returns:
        //     An System.Object hierarchical data node object.
        public object Item {


            get
            {
                return objOrgnizationChart;
            }
            
            
            
            }
        //
        // Summary:
        //     Gets the hierarchical path of the node.
        //
        // Returns:
        //     A System.String that identifies the hierarchical path relative to the current
        //     node.
        public string Path {
            get
            {
               return _objOrgnizationChart.PathEN ;

                
            }
            
            
             }
        //
        // Summary:
        //     Gets the name of the type of System.Object contained in the System.Web.UI.IHierarchyData.Item
        //     property.
        //
        // Returns:
        //     The name of the type of object that the System.Web.UI.IHierarchyData object
        //     represents.
        public string Type {


            get
            {
                return "DatabaseComponent.OrgnizationChart";
            }
            
            
            }

        // Summary:
        //     Gets an enumeration object that represents all the child nodes of the current
        //     hierarchical node.
        //
        // Returns:
        //     An System.Web.UI.IHierarchicalEnumerable collection of child nodes of the
        //     current hierarchical node.
        public IHierarchicalEnumerable GetChildren()
        {
            if (_objOrgnizationChart.ID != -1)
                return new OrganizationHierList(this._objOrgnizationChart.lstChild);
            else
                return new OrganizationHierList(new List<OrgnizationChart>());


            
        }


        //
        // Summary:
        //     Gets an System.Web.UI.IHierarchyData object that represents the parent node
        //     of the current hierarchical node.
        //
        // Returns:
        //     An System.Web.UI.IHierarchyData object that represents the parent node of
        //     the current hierarchical node.
        public IHierarchyData GetParent()
        {

            if (objOrgnizationChart.ParentID != -1)
            {
                OrganizationHier fh = new OrganizationHier(objOrgnizationChart.objParent);
                
                return fh;

            }
            else
            {
                return null;
            }
            
        }
    }
}
